package main

import (
	"fmt"
	"strings"
)

// xiaorui.cc

type Nodes3 struct {
	Order int `json:"order"`
	Attribute  string `json:"attribute"`
	DirName string `json:"dir_name"`
	BookFileId  string `json:"book_file_id"`
	Children []Nodes3 `json:"children"`
}


func  main() {


	fmt.Println("====================================================")

	//定义 一个 可以包含任意 数据类型的 切片
	s := make([]Nodes3,0)

	var  strSplits []string=strings.Split("第1.1层文件名称,第1.2层文件名称,第1.3层文件名称", ",")
	//切片的容量
	var  length int =len(strSplits)

	var fatherFirst Nodes3
	var father Nodes3
	var fatherBefor Nodes3
	var fatherLast Nodes3
	for k1,v1 :=range strSplits{

		fatherBefor=father
		father.Order =k1
		father.Attribute = "folder"
		father.DirName =v1


		if father.Order!=fatherBefor.Order{
			var children []Nodes3
			children = append(children, father)
			//下一个 节点 作为上一节点的孩子
			fatherBefor.Children = children

			fatherLast=father
		}
		if k1 ==length-1{
			fatherFirst=fatherBefor

			var f1 Nodes3
			f1.Order=length
			f1.Attribute="file"
			f1.BookFileId="dddddddddfsawfrwerfwe"
			var childrenTemp []Nodes3
			childrenTemp = append(childrenTemp, f1)
			//  最后一个 文件节点 直接 作为上一个 节点的孩子
			fatherLast.Children = childrenTemp
			s = append(s, fatherFirst)
		}
	}




	fmt.Println("================",s)

}